package org.openweathermap.service;

import org.apache.http.message.BasicNameValuePair;

import android.content.Context;

public class MakeUrl {
	Context context;
	public MakeUrl() {
	}
	
	public MakeUrl(Context context){
		this.context = context;
	}
	
	public WeatherRequest setApi(WeatherRequest request){
		request.params.add(new BasicNameValuePair(Constant.GET_APPID, Constant._APPID));
		return request;
	}
	
	public WeatherRequest setUnit(WeatherRequest request){
		request.params.add(new BasicNameValuePair(Constant.GET_UNIT, Constant._UNIT));
		return request;
	}
	
	/**
	 * ex: http://api.openweathermap.org/data/2.5/weather?q=London,uk
	 * */
	public WeatherRequest getCityByName(String country,String cityName){
		WeatherRequest request = new WeatherRequest();
		setApi(request);
		setUnit(request);
		request.url = Constant.HOST+"data/2.5/weather";
		request.params.add(new BasicNameValuePair("q",cityName+","+country));
		return request;
	}
	
	/**
	 * ex: http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139
	 * */
	public WeatherRequest getCityByCoord(String lat,String lon){
		WeatherRequest request = new WeatherRequest();
		setApi(request);
		setUnit(request);
		request.url = Constant.HOST+"data/2.5/weather";
		request.params.add(new BasicNameValuePair("lat",lat));
		request.params.add(new BasicNameValuePair("lon",lon));
		return request;
	}
	
	/**
	 * ex: http://api.openweathermap.org/data/2.5/weather?id=2172797
	 * */
	public WeatherRequest getCityById(String id){
		WeatherRequest request = new WeatherRequest();
		setApi(request);
		setUnit(request);
		request.url = Constant.HOST+"data/2.5/weather";
		request.params.add(new BasicNameValuePair("id",id));
		return request;
	}
	
	public WeatherRequest get7DaysByName(String country, String cityName){
		WeatherRequest request = new WeatherRequest();
//		request=setApi(request);
		request=setUnit(request);
		request.url = Constant.HOST+"data/2.5/forecast/daily";
		request.params.add(new BasicNameValuePair("q",cityName+","+country));
		request.params.add(new BasicNameValuePair("cnt","10"));
		return request;
	}
	
	public WeatherRequest get7DaysById(int cityId){
		WeatherRequest request = new WeatherRequest();
//		request=setApi(request);
		request=setUnit(request);
		request.url = Constant.HOST+"data/2.5/forecast/daily";
		request.params.add(new BasicNameValuePair("id",cityId+""));
		request.params.add(new BasicNameValuePair("cnt","10"));
		return request;
	}
}
